package cn.sc.allinpay.allfavour.base.widget;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * 自定义RecyclerView 子控件间距 listview形式
 * 
 * @author panyi
 *
 */
public class DecorationVert extends RecyclerView.ItemDecoration {

	private int horSpace = 0;
	private int verSpace = 0;

	public DecorationVert(Context context, int horSpaceId, int vertSpaceId) {
		if (horSpaceId != -1)
			horSpace = context.getResources().getDimensionPixelSize(horSpaceId);
		if (vertSpaceId != -1)
			verSpace = context.getResources()
					.getDimensionPixelSize(vertSpaceId);
	}

	public DecorationVert(Context context, int vertSpaceId) {
		this(context, -1, vertSpaceId);
	}

	@SuppressWarnings("deprecation")
	@Override
	public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
			RecyclerView.State state) {
		outRect.left = horSpace;
		outRect.right = horSpace;
		outRect.bottom = verSpace;

		if (parent.getChildPosition(view) == 0) {
			outRect.top = verSpace;
		}
	}
}
